package com.ghsc.ghxc.jsb.config

import android.content.Context
import android.os.Environment
import android.text.TextUtils
import com.netease.nimlib.sdk.SDKOptions
import com.netease.nimlib.sdk.mixpush.MixPushConfig
import com.netease.yunxin.kit.common.utils.ScreenUtils.getDisplayWidth
import java.io.IOException

/**
 * 项目：GuoHuaMall
 * 包名：com.ghsc.ghxc.config
 * 类名：NimSDKOptionConfig
 * 创建时间：2023/10/22 15:26
 * 创建人 @author： xiaolin
 * 描述 ：Todo...
 */
object NimSDKOptionConfig {



    fun getSDKOptions(context: Context?, appKey: String?): SDKOptions? {
        val options = SDKOptions()
        options.appKey = appKey
        options.sdkStorageRootPath = context?.let { getAppCacheDir(it) }
        options.preloadAttach = true
        options.thumbnailSize = (222.0 / 375.0 * getDisplayWidth()).toInt()
//        options.userInfoProvider = PushUserInfoProvider(context)
        options.sessionReadAck = true
        options.animatedImageThumbnailEnabled = true
        options.asyncInitSDK = true
        options.reducedIM = false
        options.checkManifestConfig = false
        options.enableTeamMsgAck = true
        options.enableFcs = false
        options.shouldConsiderRevokedMessageUnreadCount = true
        // 会话置顶是否漫游
        options.notifyStickTopSession = true
        options.mixPushConfig = buildMixPushConfig()
//        options.serverConfig = NimSDKOptionConfig.configServer(context)
        // 打开消息撤回未读数-1的开关
        options.shouldConsiderRevokedMessageUnreadCount = true
        return options
    }

    /** config app image/voice/file/log directory  */
    fun getAppCacheDir(context: Context): String? {
        var storageRootPath: String? = null
        try {
            if (context.externalCacheDir != null) {
                storageRootPath = context.externalCacheDir!!.canonicalPath
            }
        } catch (e: IOException) {
            e.printStackTrace()
        }
        if (TextUtils.isEmpty(storageRootPath)) {
            storageRootPath =
                Environment.getExternalStorageDirectory().toString() + "/" + context.packageName
        }
        return storageRootPath
    }


    private fun buildMixPushConfig(): MixPushConfig? {
        // xiaomi
//        config.xmAppId = "xiao mi push app id"; //apply in xiaomi
//        config.xmAppKey = "xiao mi push app key";//apply in xiaomi
//        config.xmCertificateName = "Certificate Name";//config in yunxin platform

        // huawei
//        config.hwAppId = "huawei app id";//apply in huawei
//        config.hwCertificateName = "Certificate Name";//config in yunxin platform

        // meizu
//        config.mzAppId = "meizu push app id";//apply in meizu
//        config.mzAppKey = "meizu push app key";//apply in meizu
//        config.mzCertificateName = "Certificate Name";//config in yunxin platform

        // fcm
//        config.fcmCertificateName = "DEMO_FCM_PUSH";

        // vivo
//        config.vivoCertificateName = "Certificate Name";//config in yunxin platform

        // oppo
//        config.oppoAppId = "oppo push app id";//apply in oppo
//        config.oppoAppKey = "oppo push app key";//apply in oppo
//        config.oppoAppSercet = "oppo push app secret"; //apply in oppo
//        config.oppoCertificateName = "Certificate Name";//config in yunxin platform
        return MixPushConfig()
    }

}